package com.cheng.cms.controller;

import com.cheng.cms.utils.FileUploadUtil;
import io.swagger.annotations.Api;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import springfox.documentation.spring.web.json.Json;

import java.io.File;
import java.util.UUID;
import java.util.concurrent.Executor;


@Controller
@Api("主页面一些组件的路由")
public class IndexController {

    /**
     * 文件上传保存地址
     */
    @Value("${project.upload.file-path}")
    String file_path;

    /**
     * 跳转到个人信息页面
     */
    @GetMapping("/userInfo")
    public String toUserInfo(String username,Model model){
        model.addAttribute("username", username);
        return "/index/userInfo";
    }

    /**
     * 跳转到修改密码页面
     */
    @GetMapping("/editPwd")
    public String toEditPwd(String username, ModelMap model){
        System.out.println("修改密码"+username);
        return "/index/editPwd";
    }

    /**
     * 修改用户头像
     */
    @PostMapping("/userPicture")
    @ResponseBody
    public String userPicture(@RequestParam("picture") MultipartFile file){
        return FileUploadUtil.pictureUpload(file,file_path);
    }

}
